package com.company.OfferGuide;

public class 连续子数组的最大和 {


    public int maxSubArray(int[] nums) {
        int[] dp = new int[nums.length];
        int max = nums[0];
        for (int i = 0; i < dp.length; i++) {
            if (i == 0) dp[i] = nums[i];
            else {
                dp[i] = Math.max(nums[i],nums[i] + dp[i - 1]);
                max = Math.max(dp[i],max);
            }
        }

        return max;

    }

}
